package com.google.code.netcheckin.util;

import java.text.Collator;
import java.util.Comparator;

import com.google.code.netcheckin.aprs.Station;

/**
  * An implementation of Comparator that can be used to collate
  * two Station objects based on their call signs (APRS object names).
  * @author Dick Repasky
  *
*/

public class StationCallCollator implements Comparator {

	protected Collator stringCollator;

	public StationCallCollator() {
		stringCollator = Collator.getInstance();
		
	}
	
	public int compare(Station stna, Station stnb) {
		String calla = getCallsign(stna);
		String callb = getCallsign(stnb);
		return stringCollator.compare(calla, callb);
	}

	public int compare(Object obja, Object objb) {
		if (obja instanceof Station && objb instanceof Station) {
			return compare((Station)obja, (Station)objb);
		} else {
			return stringCollator.compare(obja, objb);
		}
	}

	public boolean equals(Object obj) {
		return getClass().getName().equals(obj.getClass().getName());
	}

	protected String getCallsign(Station stn) {
		return stn.getCallsign().toUpperCase();
	}

}
